package urltool

import (
	"errors"
	"github.com/zeromicro/go-zero/core/logx"
	"net/url"
	"path"
)

func GetBasePath(url1 string) (string, error) {
	myurl, err := url.Parse(url1)
	if err != nil {
		logx.Errorw("url.Parse failed ", logx.Field("err", err))
		return "", err
	}
	if len(myurl.Host) == 0 {
		return "", errors.New("url host is empty")
	}
	basePath := path.Base(myurl.Path)
	return basePath, nil
}
